/*
 * Copyright (C) 2008 GeoScheduler Team, as stated on <http://www.geoscheduler.org/authors>.
 * 
 * This file is part of GeoScheduler.
 * 
 * GeoScheduler is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * GeoScheduler is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with GeoScheduler. If not, see <http://www.gnu.org/licenses/>.
 */
package org.geoscheduler.commons.qbuilder;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

import org.geoscheduler.commons.qbuilder.TableDecl;
import org.geoscheduler.model.Account;
import org.geoscheduler.model.Account.AccountType;

/**
 * FIXME [lko] comment me!
 *
 * @author lko
 */
class AccountDecl extends TableDecl<Account> {

	public static final AccountDecl INSTANCE = new AccountDecl();

	protected AccountDecl() {
		super("GS_ACCOUNT", Account.class);
	}

	public static ColumnDecl<Account, Long> Id = new ColumnDecl<Account, Long>(INSTANCE, "id", Long.class, true) {
		@Override
		public Long getValue(Account instance) {
			return instance.getId();
		}

		@Override
		public void setValue(Account instance, ResultSet rs) throws SQLException {
			instance.setId(rs.getLong(name()));
		}
	};
	public static ColumnDecl<Account, String> Login = new ColumnDecl<Account, String>(INSTANCE, "login",
			String.class) {
		@Override
		public String getValue(Account instance) {
			return instance.getLogin();
		};

		@Override
		public void setValue(Account instance, ResultSet rs) throws SQLException {
			instance.setLogin(rs.getString(name()));
		};
	};
	public static ColumnDecl<Account, String> Passwd = new ColumnDecl<Account, String>(INSTANCE, "passwd",
			String.class) {

		@Override
		public String getValue(Account instance) {
			return instance.getPasswd();
		}

		@Override
		public void setValue(Account instance, ResultSet rs) throws SQLException {
			instance.setPasswd(rs.getString(name()));
		}

	};
	public static ColumnDecl<Account, AccountType> AccountType = new ColumnDecl<Account, AccountType>(INSTANCE,
			"account_type", AccountType.class) {

		@Override
		public AccountType getValue(Account instance) {
			// return instance.();
			// FIXME [lukas] temporary skipped
			return null;
		}

		@Override
		public void setValue(Account instance, ResultSet rs) throws SQLException {
			// instance.setAccoutType(org.geoscheduler.model.Account.AccountType.values()[rs.getInt(name())]);
			// FIXME [lukas] temporary skipped

		}

	};
	public static ColumnDecl<Account, Date> Created = new ColumnDecl<Account, Date>(INSTANCE, "created", Date.class) {

		@Override
		public Date getValue(Account instance) {
			return instance.getCreated();
		}

		@Override
		public void setValue(Account instance, ResultSet rs) throws SQLException {
			instance.setCreated(rs.getDate(name()));
		}

	};
	public static ColumnDecl<Account, Date> Acessed = new ColumnDecl<Account, Date>(INSTANCE, "acessed", Date.class) {

		@Override
		public Date getValue(Account instance) {
			return instance.getAccessed();
		}

		@Override
		public void setValue(Account instance, ResultSet rs) throws SQLException {
			instance.setAccessed(rs.getDate(name()));
		}
	};
}